<?php
namespace app\common\component\seed;

use app\common\model\Seed as SeedModel;

class SeedService {
	public function find($user_id) {
		$seedModelGet = SeedModel::get(['user_id' => $user_id]);

		if(!$seedModelGet) {
			$data['user_id'] = $user_id;
			
			return $this -> create($data);
		}

		return [
			'code' => 0,
			'data' => ['seed' => $seedModelGet]
		];;
	}
	
	public function create($data) {
		$seedModel = SeedModel::create($data);
		
		if($seedModel) {
			return [
				'code' => 0,
				'data' => ['seed' => $seedModel]
			];
		}

		return [
			'code' => -1,
			'message' => '创建失败,seed'
		];
	}
}